//小程序自定义配置dump工具函数的封装
import observable from '@src/store/mall'

import router from "@src/router";

const accountInfo = wx.getAccountInfoSync();
export function dumpFunc(dump, biz) {
	console.log('dumpFunc-dump', dump)
	console.log('dumpFunc-insideParams', JSON.parse(dump.insideParams))
	console.log('dumpFunc-biz', biz)
	if (dump.type == 'INSIDE') {
		let insideParams = JSON.parse(dump.insideParams);
		//携带参数
		if (dump.path == 'sp-mall/pages/goods-detail/index') {
			let urlParams = {
				storeId: observable.storeId,
				goodsSerial: insideParams.goodsSerial
			}
			router.push({
				name: "mall/goods-detail",
				params: urlParams
			})
		} else if (dump.path == 'sp-mall/pages/active-page/index') {
			let urlParams = {
				pageId: insideParams.pageId
			}
			router.push({
				name: "mall/active-page",
				params: urlParams
			})
		} else if (dump.path == 'sp-member/pages/redemptionDetails/main') {
			let urlParams = {
				productNo: insideParams.commonCode
			}
			router.push({
				path: dump.path,
				params: urlParams
			})
		}else if (dump.path == 'sp-member/pages/customerForm/main') {
			let urlParams = {
				pageId: insideParams.commonCode
			}
			router.push({
				path: dump.path,
				params: urlParams
			})
		}
		else if (dump.path == 'sp-member/pages/couponDetailNew/main') {
			let urlParams = {
				prototypeId: insideParams.commonCode
			}
			router.push({
				path: dump.path,
				params: urlParams
			})
		} else if (dump.path == 'sp-member/pages/consumeActivityDetail/main') {
			let urlParams = {
				activityCode: insideParams.commonCode
			}
			router.push({
				path: dump.path,
				params: urlParams
			})
		} else if (dump.path == 'code-order/pages/index/main') {
			// console.log()
			// if(getApp().globalData.dinnerType == 0){
			//  router.push({name: 'codeorder/shop',})
			// }else{
			let urlParams = {};
			if (insideParams.pageId) {
				urlParams = {
					pageId: insideParams.pageId
				}
			}
			router.push({
				path: dump.path,
				params: urlParams
			})
			// }
		} else {
			let urlParams = {};
			if (insideParams.pageId) {
				urlParams = {
					pageId: insideParams.pageId
				}
			}
			router.push({
				path: dump.path,
				params: urlParams,
				isTab: true
			})
		}
	} else if (dump.type == 'FEATURE') {
		let featureParams = JSON.parse(dump.featureParams)
		//拨打电话
		if (dump.feature == 'CALL') {
			wx.makePhoneCall({
				phoneNumber: featureParams.phone
			})
			//暂时不做
		} else if (dump.feature == 'CONTACT') { //微信客服助手

		}
	} else if (dump.type == 'WXAPP') {
		//跳转到另外一个小程序
		let appId = accountInfo.miniProgram.appId
		//如果是当前小程序 跳到本小程序的页面
		if (appId == dump.appId) {
			router.push({
				path: dump.path
			})
		} else {
			wx.navigateToMiniProgram({
				appId: dump.appId,
				path: dump.path,
				//develop	开发版; trial	体验版;release	正式版
				envVersion: 'release',
				success(res) {
					// 打开成功
				}
			})
		}

	} else if (dump.type == 'URL') {
		router.push({
			name: 'mall/inside-url',
			params: {
				url: dump.url,
				title: dump.title || ''
			}
		})
	} else if (dump.type == 'URL_KF') {
		console.log('企业客服')
		let {
			corpId
		} = JSON.parse(biz.params)
		wx.openCustomerServiceChat({
			extInfo: {
				url: dump.url
			},
			corpId: corpId,
			success(res) {},
			fail(res) {
				wx.showToast({
					title: '当前无客服', //提示文字
					icon: "none",
					duration: 2000, //显示时长
				})
			},
		})
	}
}
export function tabDumpFunc(dump) {
	if (dump.openType == 'INSIDE') {
		let insideParams = JSON.parse(dump.openInsideParams);
		//目前只有商品详情页需要携带参数
		if (dump.path == 'sp-mall/pages/goods-detail/index') {
			let urlParams = {
				storeId: observable.storeId,
				goodsSerial: insideParams.goodsSerial
			}
			router.push({
				name: "mall/goods-detail",
				params: urlParams
			})
		} else if (dump.path == 'sp-mall/pages/active-page/index') {
			let urlParams = {
				pageId: insideParams.pageId
			}
			router.push({
				name: "mall/active-page",
				params: urlParams
			})
		} else {
			let urlParams = {};
			if (insideParams.pageId) {
				urlParams = {
					pageId: insideParams.pageId
				}
			}
			console.log("dump.path", dump.openPath)
			router.push({
				path: dump.openPath,
				params: urlParams
			})
		}
	} else if (dump.openType == 'FEATURE') {
		let featureParams = JSON.parse(dump.featureParams)
		//拨打电话
		if (dump.feature == 'CALL') {
			wx.makePhoneCall({
				phoneNumber: featureParams.phone
			})
			//暂时不做
		} else if (dump.feature == 'CONTACT') { //微信客服助手

		}
	} else if (dump.openType == 'WXAPP') {
		//跳转到另外一个小程序
		wx.navigateToMiniProgram({
			appId: dump.appId,
			path: dump.path,
			//develop	开发版; trial	体验版;release	正式版
			envVersion: 'release',
			success(res) {
				// 打开成功
			}
		})
	} else if (dump.openType == 'URL') {
		router.push({
			name: 'mall/inside-url',
			params: {
				url: dump.url
			}
		})
	}
}
